package com.jingxi.rest.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jingxi.common.pojo.EasyUIDataGridResult;
import com.jingxi.common.pojo.JingXiResult;
import com.jingxi.common.util.JsonUtils;
import com.jingxi.mapper.TbItemMapper;
import com.jingxi.model.TbItem;
import com.jingxi.model.TbItemExample;
import com.jingxi.model.TbItemExample.Criteria;
import com.jingxi.rest.pojo.SolrResult;
import com.jingxi.rest.service.SearchService;

@Controller
public class SearchController {

	@Autowired
	private SearchService searchService;

	@RequestMapping(value = "/search")
	@ResponseBody
	public JingXiResult search(@RequestParam("q") String q,
			@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "rows", defaultValue = "16") Integer rows) throws UnsupportedEncodingException {
			q = new String(q.getBytes("ISO-8859-1"), "UTF-8");
		JingXiResult jing = searchService.search(q, page, rows);
		return jing;
	}

/*	*//**
	 * 更新索引库商品数据
	 * 
	 * @param item
	 * @return
	 *//*
	@RequestMapping(value = "update/item", method = RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<Void> updateItem(@RequestBody TbItem item) {
		try {
			this.searchService.updateItem(item);
			return ResponseEntity.ok(null);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 500
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

	}*/

}
